package com.dx.wx.controller;

import com.dx.wx.service.DxShopService;
import com.dx.wx.service.DxUserService;
import com.dx.wx.util.DxUtil;
import com.ejlchina.data.Array;
import com.ejlchina.data.ListArray;
import com.ejlchina.data.Mapper;
import com.yf.annotation.IgnoreAuth;
import com.yf.annotation.LoginUserId;
import com.yf.response.R;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/dx/ct/user")
public class ApiDxCtUserController {

    @Autowired
    private DxUserService dxUserService;


    @GetMapping("/list")
    public R list(@LoginUserId Long phone, String filterPhone, String appId) {
        String sPhone = String.valueOf(phone);
        if (filterPhone != null && !filterPhone.equals("")) {
            sPhone = filterPhone;
        }
        Mapper userMapper = dxUserService.findByMobile(sPhone, appId);
        Array userList;
        Boolean isMan = false;//是否是主管
        //查看用户级别
        if (userMapper.getInt("field_Rh3vp__c") == 5) {//总监
            userList = dxUserService.findByTopTop(phone, appId);
            isMan = true;
        } else if (userMapper.getInt("field_Rh3vp__c") == 6) {//经理
            userList = dxUserService.findByTop(phone, appId);
        } else {
            return R.ok(Arrays.asList(userMapper).toString()); //直接返回本人
        }
       if(isMan){
           //是总监 找出下面的业务员
           Array topList =  dxUserService.findByTop(Long.valueOf(sPhone),appId);
           return R.ok(userList.toString()).putExtra("isMan", true).putExtra("topList",topList.toString());
       }else {
           return R.ok(userList.toString()).putExtra("isMan", false);
       }


    }


}
